package com.tiantianfresh.view.service.impl;

import com.tiantianfresh.model.dao.OrderMapper;
import com.tiantianfresh.model.dao.OrderSpecificMapper;
import com.tiantianfresh.model.pojo.Order;
import com.tiantianfresh.model.pojo.OrderSpecific;
import com.tiantianfresh.model.pojo.OrderState;
import com.tiantianfresh.view.service.ShopOrderService;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author FANGAO
 * @date 2021/12/6 - 下午 14:28
 */
@Service
public class ShopOrderServiceImpl implements ShopOrderService {
    @Resource
    private OrderMapper orderMapper;
    @Resource
    private OrderSpecificMapper orderSpecificMapper;

    @Override
    public List<Order> queryShopOrder(Integer userid) {
        List<Order> orders = orderMapper.queryShopOrder(userid);
        for (Order order : orders) {
            List<OrderSpecific> orderSpecifics = orderSpecificMapper.queryOrderSpecificOrderId(order.getOrderid(), userid);
            order.setOrderSpecifics(orderSpecifics);
        }
        return orders;
    }

    @Override
    public boolean receiving(Map<String,Object> map) {
        map.put("orderState",4);
        if (orderMapper.updateOrderState(map)>0)return true;
        return false;
    }

    @Override
    public List<OrderState> queryOrderStateAll() {
        return orderMapper.queryOrderStateAll();
    }
}
